package com.woniuxy.springboot.configurationfile.controller;

import com.woniuxy.springboot.configurationfile.bean.Person;
import com.woniuxy.springboot.configurationfile.bean.Phone;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@Scope("prototype")
public class HiController {
    @Autowired
    private Person person;
    @GetMapping("/getInfo")
    public String getInfo(){
        return "我是"+person.getSchool()+"的"+person.getName();
    }
    @GetMapping(value = "/getFruit")
    public String getFruit(){
        String[] fruit = person.getFruit();
        StringBuilder sb=new StringBuilder();
        if(fruit!=null&&fruit.length>0){
            for (int i = 0; i <fruit.length ; i++) {
                sb.append(fruit[i]);
                sb.append(",");
            }
        }
        sb.delete(sb.length()-1,sb.length());
        return sb.toString();
    }
    @GetMapping(value = "/getHobby")
    public Set<String> getHobby(){
        Set<String> hobby = person.getHobby();
        return hobby;
    }
    @GetMapping(value = "/getPhone")
    public List<Phone> getPhone(){
        return person.getPhones();
    }
    @GetMapping(value = "/getCoutry")
    public Map<String,String> getCoutry(){
        return person.getCountrys();
    }
    @GetMapping(value = "/getBirthday")
    public Date getBirthday(){
        return person.getBirthday();
    }
    @GetMapping(value = "/getPrice")
    public int getPrice(){
        return person.getPrice();
    }
    @GetMapping(value = "/getIntroduce")
    public String getIntroduce(){
        return person.getIntroduce();
    }

    @GetMapping(value = "/getRandom")
    public int getRandom(){
        Random random=new Random();
        return random.nextInt();
    }
}
